<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ include file="/WEB-INF/view/common/tag.jsp" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>艺术展览预约</title>

    <link rel="stylesheet" href="${baseurl}/lib/yueqain/css/yueqian.all.css" media="all">
</head>
<body class="yueqian-container">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">艺术展名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="exhibitionName" placeholder="" class="layui-input">
                </div>
                <button class="yueqian-btn yueqian-btn-md yueqian-btn-primary" lay-submit lay-filter="search">
                    <i class="layui-icon layui-icon-search"></i>
                    查询
                </button>
                <button type="reset" class="yueqian-btn yueqian-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </form>
    </div>
</div>

<div class="layui-card">
    <div class="layui-card-body">
        <%--<div class="layui-btn-group operateTable" style="margin: 5px">--%>
            <%--<button class="yueqian-btn yueqian-btn-primary yueqian-btn-md" data-type="add">--%>
                <%--<i class="layui-icon layui-icon-add-1"></i>--%>
                <%--新增--%>
            <%--</button>--%>
        <%--</div>--%>
        <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
    </div>
</div>

<!--操作-->
<script type="text/html" id="tableTool">
    <%--<a class="layui-btn layui-btn-xs"  lay-event="update">修改</a>--%>
    <%--<a class="layui-btn layui-btn-xs"  lay-event="del">删除</a>--%>

    {{#if (d.isApprove == 0) { }}
    <a class="layui-btn layui-btn-xs"  lay-event="approve">审批</a>
    {{# } }}
</script>


<script type="text/html" id="isApproveTpl">
    {{#if (d.isApprove == 0) { }}
    <span class="layui-green">未审批</span>
    {{# }else if(d.isApprove == 1){ }}
    <span class="layui-orange">已审批</span>
    {{# } }}
</script>

<script src="${baseurl}/lib/layui/layui.js" charset="utf-8"></script>
<script src="${baseurl}/lib/layui_custom/Hlayui.js" charset="utf-8"></script>
<script>
    //JavaScript代码区域
    layui.use(['element', 'table', 'form', 'jquery', 'layer', 'layerCustom'], function () {
        var element = layui.element;
        table = layui.table,
            $ = layui.jquery,
            layerCustom = layui.layerCustom,
            layer = layui.layer,
            form = layui.form;

        var myTalbe = table.render({
            elem: '#tableId'
            , url: BaseUrl + 'galleryAppoint/list'
            ,   skin: 'line'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'galleryName', title: '展览馆名称',width:150}
                , {field: 'exhibitionName', title: '展览名称',width:150}
                , {field: 'appointUserName', title: '预约人',width:150}
                , {field: 'appointTime', title: '预约时间',width:150}
                , {field: 'isApprove',width:100, title: '审批状态',align:'center',templet:"#isApproveTpl"}
                , {field: 'createTime', title: '创建时间',width:170}
                , {field: 'approveUserName', title: '审批人',width:150}
                , {field: 'appointNo', title: '预约号',width:200}
                , {field: 'approveTime', title: '审批时间时间',width:200}
                , {title: '操作', toolbar: '#tableTool', fixed: "right", align: "center",width:170}
            ]]
            , page: true
        });

        form.on("submit(search)", function (data) {
            myTalbe.reload({
                where: data.field,
                page: {curr: 1}
            });
            return false;
        });

        table.on("tool(tableFilter)", function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case "update":
                    update(data);
                    break;
                case "del":
                    del(data);
                case "approve":
                    approve(data);
                break;
            }
        });

        $('.operateTable .yueqian-btn').on('click', function () {
            var type = $(this).data('type');
            switch (type) {
                case "add":
                    add();
                    break;
            }
        });

        function add() {
            layerCustom.open("添加展览", BaseUrl + 'galleryAppoint/add', "700px", "550px", function (layero, index) {

            }, function () {
                myTalbe.reload();
            })
        }



        function update(data) {
            layerCustom.open("修改展览信息", BaseUrl + 'galleryAppoint/edit', "700px", "450px", function (layero, index) {

                var iframeWin = window[layero.find("iframe")[0]["name"]];
                iframeWin.initForm(data);
            }, function () {
                myTalbe.reload();
            })
        }

        function del(data){
            layerCustom.confirm("是否要删除该记录",function () {
               var loading = layer.load();
                var params ={
                    id:data.id
                }
                $.ajax({
                    url: BaseUrl + "galleryAppoint/remove",
                    data:params,
                    dataType: 'json',
                    type: 'post',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layerCustom.greenLaughMsg(result.msg,function () {
                                myTalbe.reload();
                            });
                        } else {
                            layerCustom.redCryMsg(result.msg);
                        }
                    }
                })
            })
        }


        /**
         * 审批
         * @param data
         */
        function approve(data) {
            layerCustom.confirm("是否进行审批?",function () {
                $.ajax({
                    url: BaseUrl + "galleryAppoint/approve",
                    type: "post",
                    dataType: "json",
                    data: {
                        id:data.id
                    },
                    beforeSend: function () {
                        layer.load(2);
                    },
                    success: function (result) {
                        if (result.success) {
                            layerCustom.greenLaughMsg(result.msg,function () {
                                myTalbe.reload();
                            })
                        }
                        layer.closeAll('loading');
                    },
                    error: function () {
                        layer.closeAll('loading');
                    }
                });
            })
        }

    });
</script>
</body>
</html>

